package com.rs.game.player.dialogues;

import com.rs.game.player.content.Decanting;
import com.rs.game.tasks.WorldTask;
import com.rs.game.tasks.WorldTasksManager;
import com.rs.utils.ShopsHandler;

public class Shops extends Dialogue {

	int npcId;
	
	@Override
	public void start() {
		sendOptionsDialogue("Shops", "Combat shops", "Skilling shops", "Vote shop", "Loyalty shop", "Supplies shops");
		
	}

	@Override
	public void run(int interfaceId, int componentId) {
		if (stage == -1 ) {
			if (componentId == OPTION_1) {
				sendOptionsDialogue("Combat Shops", "Melee shops", "Ranging shops", "Magic shops", "Back");
				stage = 0;
			}
			if (componentId == OPTION_2) {
				sendOptionsDialogue("Skilling shops", "Crafting shop", "Herblore shops", "Woodcutting shop", "Mining shop", "Hunting shop");
				stage = 1;
			}
			if (componentId == OPTION_3) {
				sendOptionsDialogue("Voting Shops", "Weappons and Armour", "Cosmetics", "Back");
				stage = 7;
			}
			if (componentId == OPTION_4) {
				ShopsHandler.openShop(player, 37);	
				end ();
			}
			if (componentId == OPTION_5) {
				sendOptionsDialogue("Supplies shops", "Supply shop", "General store", "Back");
				stage = 2;
			}
		} else if (stage == 0) {
			if (componentId == OPTION_1) {
				sendOptionsDialogue("Melee shops", "Melee weapons", "Melee armour", "Back");
				stage = 3;
			}
			if (componentId == OPTION_2) {
				sendOptionsDialogue("Ranging shops", "Ranging weapons", "Ranging armour", "Ammunition", "Back");
				stage = 4;
			}
			if (componentId == OPTION_3) {
				sendOptionsDialogue("Magic shops", "Magic weapons & armour", "Magic runes", "Back");
				stage = 5;
			}
			if (componentId == OPTION_4) {
				player.getDialogueManager().startDialogue("Shops");
			}
		} else if (stage == 1) {
			if (componentId == OPTION_1) {
				ShopsHandler.openShop(player, 18);
				end ();
			}
			if (componentId == OPTION_2) {
				sendOptionsDialogue("Herblore shops", "Herbs shops", "Second ingredients shop", "Decanting", "Back");
				stage = 6;
			}
			if (componentId == OPTION_3) {
				ShopsHandler.openShop(player, 19);
				end ();
			}
			if (componentId == OPTION_4) {
				ShopsHandler.openShop(player, 20);
				end ();
			}
			if (componentId == OPTION_5) {
				ShopsHandler.openShop(player, 21);
				end ();
			}
		} else if (stage == 2) {
			if (componentId == OPTION_1) {
				ShopsHandler.openShop(player, 3);
				end ();
			}
			if (componentId == OPTION_2) {
				ShopsHandler.openShop(player, 1);
				end ();
			}
			if (componentId == OPTION_3) {
				player.getDialogueManager().startDialogue("Shops");
			}
		} else if (stage == 3) {
			if (componentId == OPTION_1) {
				ShopsHandler.openShop(player, 4);
				end ();
			}
			if (componentId == OPTION_2) {
				ShopsHandler.openShop(player, 5);
				end ();
			}
			if (componentId == OPTION_3) {
				sendOptionsDialogue("Combat Shops", "Melee shops", "Ranging shops", "Magic shops", "Back");
				stage = 0;			
			}
		} else if (stage == 4) {
			if (componentId == OPTION_1) {
				ShopsHandler.openShop(player, 6);
				end ();
			}
			if (componentId == OPTION_2) {
				ShopsHandler.openShop(player, 30);
				end ();
			}			
			if (componentId == OPTION_3) {
				ShopsHandler.openShop(player, 31);
				end ();
			}
			if (componentId == OPTION_4) {
				sendOptionsDialogue("Combat Shops", "Melee shops", "Ranging shops", "Magic shops", "Back");
				stage = 0;	
			}
		} else if (stage == 5) {
			if (componentId == OPTION_1) {
				ShopsHandler.openShop(player, 7);
				end ();
			}
			if (componentId == OPTION_2) {
				ShopsHandler.openShop(player, 8);
				end ();
			}
			if (componentId == OPTION_3) {
				sendOptionsDialogue("Combat Shops", "Melee shops", "Ranging shops", "Magic shops", "Back");
				stage = 0;
			}
		} else if (stage == 6) {
			if (componentId == OPTION_3) {
				sendNPCDialogueNoContinue(player, npcId, 9827, "Decanting...");
				player.lock(5);
				end();
				WorldTasksManager.schedule(new WorldTask() {
					@Override
					public void run() {
						Decanting decanting = new Decanting(player);
						decanting.decant();
						sendNPCDialogueNoContinue(player, npcId, 9827,
								"There yer go, chum!");
						WorldTasksManager.schedule(new WorldTask() {
							@Override
							public void run() {
								closeNoContinueDialogue(player);
								end();
							}
						}, 2);
					}
				}, 5);
			} else {
				end();
				if(componentId == OPTION_2) {
					ShopsHandler.openShop(player, 23);
					end();
				}
				if (componentId == OPTION_1) {
					ShopsHandler.openShop(player, 22);
					end();
				}
			}		
		} else if (stage == 7) {
			if (componentId == OPTION_1) {
				ShopsHandler.openShop(player, 10);
				end ();
			}
			if (componentId == OPTION_2) {
				ShopsHandler.openShop(player, 39);
				end ();
			}
			if (componentId == OPTION_3) {
				player.getDialogueManager().startDialogue("Shops");
			}
		}
	}

	@Override
	public void finish() {
		// TODO Auto-generated method stub
		
	}

}
